/*
 * GameStateRequestHandler.java
 * Copyright 2012 Erik Strelzoff
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.magelord.servlet;

import java.util.Map;

/**
 * Sends necessary commands to the client to bring their local UI to the
 * correct current game state.
 */
public class GameStateRequestHandler extends RequestHandler {
	
	private int m_state = 0;
	
	public GameStateRequestHandler(MageLordServletContext context) {
		super(context);
	}
	
	public Object handleRequest(Map<String, String[]> parameterMap) {
		
		m_context.log("GameStateRequestHandler:  Handling request");
		
		// We will make an array of commands to send to the client
		// to bring them up to the correct state.  The array might
		// be empty if there is nothing to do.  The client will poll
		// this handler for new status info.
		
		// TBI:  Move this component into Game Logic layer
//		JSONArray commandArray = new JSONArray();
//		
//		// For testing ...  just make a Command which moves a piece on the board.
//		JSONObject command = new JSONObject();
//		command.put("name", "movePiece");
//		command.put("pieceId", 1);
//		// Better way to specify tile coordinates?
//		command.put("tilex", 1 + m_state);
//		command.put("tiley", 1 + m_state);
//		// Each time we poll, change our state!
//		m_state++;
//		commandArray.put(command);
//		
//		JSONObject response = new JSONObject();
//		response.put("commands", commandArray);
//		return response;
		return null;
	}
	
	public String toString() {
		return "GameStateRequestHandler";
	}
}
